library(cfbfastR)
library(gt)
library(gtExtras)
library(data.table)
library(tidyverse)
library(magrittr)
library(janitor)
gt_theme_f5 <- function(gt_object, ...) {
gt_object %>%
opt_table_font(
font = list(
google_font("Roboto"),
default_fonts()
),
weight = 400
) %>%
tab_style(
locations = cells_title("title"),
style = cell_text(
font = google_font("Roboto"),
weight = 700
)
) %>%
tab_style(
locations = cells_title("subtitle"),
style = cell_text(
font = google_font("Roboto"),
color = "gray65",
weight = 400
)
) %>%
tab_style(
style = list(
cell_borders(
sides = "top", color = "black", weight = px(0)
),
cell_text(
font = google_font("Roboto"),
#transform = "uppercase",
v_align = "bottom",
size = px(14),
weight = 'bold'
)
),
locations = list(
gt::cells_column_labels(),
gt::cells_stubhead()
)
) %>%
tab_options(
column_labels.background.color = "floralwhite",
data_row.padding = px(7.5),
heading.border.bottom.style = "none",
table.border.top.style = "none", # transparent
table.border.bottom.style = "none",
column_labels.font.weight = "bold",
column_labels.border.top.style = "none",
column_labels.border.bottom.width = px(2),
column_labels.border.bottom.color = "black",
row_group.border.top.style = "none",
row_group.border.top.color = "black",
row_group.border.bottom.width = px(1),
row_group.border.bottom.color = "floralwhite",
stub.border.color = "floralwhite",
stub.border.width = px(0),
source_notes.font.size = 12,
source_notes.border.lr.style = "none",
table.font.size = 16,
heading.align = "left",
table.background.color = "floralwhite",
table_body.hlines.color = 'gray90',
...
)
}
stats <- cfbfastR::cfbd_stats_season_player(2024,
season_type = "both",
conference = "MWC")
rush <- stats |>
filter(rushing_yds > 500) |>
mutate(passing_completions = ifelse(is.na(passing_completions), 0, passing_completions)) |>
filter(passing_completions < 5) |>
select(team, athlete_id, player, rushing_car, rushing_yds, rushing_td, rushing_long, rushing_ypc, fumbles_lost, fumbles_fum, receiving_rec, receiving_yds, receiving_td, receiving_long)
usage <- cfbd_player_usage(2024,
conference = "MWC")
rb_usage <- usage |>
filter(position == "RB") |>
select(athlete_id, usg_overall, usg_rush, usg_pass)
info <- cfbd_team_info()
## New names:
## 2025-06-07 10:33:47.166122:Invalid arguments or no team data available!
## • `id` -> `id...1`
## • `id` -> `id...14`
rush %<>%
left_join(info %>% select(school, logo), by = c("team" = "school"))
rbs <- fread("~/Downloads/2025 MW RBs.csv") %>%
clean_names()
rbs %>%
filter(!is.na(yards_per_attempt)) %>%
mutate(rank = row_number(),
yards = as.numeric(yards)) %>%
select(rank, everything()) %>%
view()
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `yards = as.numeric(yards)`.
## Caused by warning:
## ! NAs introduced by coercion
#Try that again, but I think I need to remove the whitespace from yards first
rbs <- fread("~/Downloads/2025 MW RBs.csv") %>%
clean_names() %>%
mutate(rank = row_number()) %>%
arrange(rank) %>%
mutate(rank = paste0(row_number(), ".")) %>%
select(rank, everything()) %>%
mutate(yards = as.numeric(str_remove_all(yards, "[,\\s]"))) %>%
filter(!is.na(yards)) %>%
mutate(school = ifelse(school == "San Jose State", "San José State", school)) %>%
left_join(info %>% select(school, logo), by = c("school" = "school"))
# rush %<>%
# mutate(team = ifelse(team == "San José State", "San Jose State", team))
# plays <- load_cfb_pbp(2024)
#
#
# plays %>%
# filter(!is.na(rush_player_id)) %>%
# view()
#
#
# plays <- cfbd_pbp_data(2024, epa_wpa = T)
#
#
# #select(rush_player_id, rusher_player_name) %>%
# group_by(rusher_player_name) %>%
# summarize(mean = mean(EPA, na.rm = TRUE)) %>%
# view()
#
#
# plays <- cfbfastR::espn_cfb_pbp()
#
#
# cfbfastR::
#
rbs %>%
select(rank, logo, player, yards, yards_per_attempt, pff_rush_grade, missed_tackles_forced) %>%
gt() %>%
gt_theme_f5() %>%
gt_img_rows(
columns = logo,
height = 30
) %>%
tab_header(
title = "Mountain West Running Backs",
subtitle = "Top 15"
) %>%
cols_label(
logo = "",
rank = "Rank",
player = "Player",
yards = "Yards",
yards_per_attempt = "YPA",
pff_rush_grade = "PFF Rush Grade",
missed_tackles_forced = "Missed Tackles Forced"
) %>%
data_color(yards, palette = "rcartocolor::Tropic", domain = c(100, 1400), reverse = T) %>%
data_color(yards_per_attempt, palette = "rcartocolor::Tropic", domain = c(3.5, 8), reverse = T) %>%
data_color(pff_rush_grade, palette = "rcartocolor::Tropic", domain = c(60, 95), reverse = T) %>%
tab_options(data_row.padding = '0px')